home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / src / gdevcif.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-01  |  3.4 KB  |  102 lines

  1. /* Copyright (C) 1993 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of AFPL Ghostscript.
  4.   
  5.   AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  6.   distributor accepts any responsibility for the consequences of using it, or
  7.   for whether it serves any particular purpose or works at all, unless he or
  8.   she says so in writing.  Refer to the Aladdin Free Public License (the
  9.   "License") for full details.
  10.   
  11.   Every copy of AFPL Ghostscript must include a copy of the License, normally
  12.   in a plain ASCII text file named PUBLIC.  The License grants you the right
  13.   to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14.   conditions described in the License.  Among other things, the License
  15.   requires that the copyright notice and this notice be preserved on all
  16.   copies.
  17. */
  18.  
  19. /*$Id: gdevcif.c,v 1.2 2000/09/19 19:00:12 lpd Exp $*/
  20. /*
  21.   CIF output driver
  22.  
  23.    The `Fake bitmapped device to estimate rendering time' 
  24.    slightly modified to produce CIF files from PostScript.
  25.    So anyone can put a nice logo free on its chip!
  26.    Frederic Petrot, petrot@masi.ibp.fr */
  27.  
  28. #include "gdevprn.h"
  29.  
  30. /* Define the device parameters. */
  31. #ifndef X_DPI
  32. #  define X_DPI 72
  33. #endif
  34. #ifndef Y_DPI
  35. #  define Y_DPI 72
  36. #endif
  37.  
  38. /* The device descriptor */
  39. private dev_proc_print_page(cif_print_page);
  40. gx_device_printer far_data gs_cif_device =
  41.   prn_device(prn_std_procs, "cif",
  42.     DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
  43.     X_DPI, Y_DPI,
  44.     0,0,0,0,
  45.     1, cif_print_page);
  46.  
  47. /* Send the page to the output. */
  48. private int
  49. cif_print_page(gx_device_printer *pdev, FILE *prn_stream)
  50. {    int line_size = gdev_mem_bytes_per_scan_line((gx_device *)pdev);
  51.     int lnum;
  52.     byte *in = (byte *)gs_malloc(line_size, 1, "cif_print_page(in)");
  53.     char *s;
  54.     int scanline, scanbyte;
  55.     int length, start; /* length is the number of successive 1 bits, */
  56.                /* start is the set of 1 bit start position */
  57.  
  58.     if (in == 0)
  59.         return_error(gs_error_VMerror);
  60.  
  61.     if ((s = strchr(pdev->fname, '.')) == NULL)
  62.         length = strlen(pdev->fname) + 1;
  63.     else
  64.         length = s - pdev->fname;
  65.     s = (char *)gs_malloc(length, sizeof(char), "cif_print_page(s)");
  66.  
  67.     strncpy(s, pdev->fname, length);
  68.     *(s + length) = '\0';
  69.     fprintf(prn_stream, "DS1 25 1;\n9 %s;\nLCP;\n", s);
  70.     gs_free(s, length, 1, "cif_print_page(s)");
  71.  
  72.    for (lnum = 0; lnum < pdev->height; lnum++) {   
  73.       gdev_prn_copy_scan_lines(pdev, lnum, in, line_size);
  74.       length = 0;
  75.       for (scanline = 0; scanline < line_size; scanline++)
  76. #ifdef TILE            /* original, simple, inefficient algorithm */
  77.          for (scanbyte = 0; scanbyte < 8; scanbyte++)
  78.             if (((in[scanline] >> scanbyte) & 1) != 0)
  79.                fprintf(prn_stream, "B4 4 %d %d;\n",
  80.                   (scanline * 8 + (7 - scanbyte)) * 4,
  81.                   (pdev->height - lnum) * 4);
  82. #else                /* better algorithm */
  83.          for (scanbyte = 7; scanbyte >= 0; scanbyte--)
  84.             /* cheap linear reduction of rectangles in lines */
  85.             if (((in[scanline] >> scanbyte) & 1) != 0) {
  86.                if (length == 0)
  87.                   start = (scanline * 8 + (7 - scanbyte));
  88.                length++;
  89.             } else {
  90.                if (length != 0)
  91.                   fprintf(prn_stream, "B%d 4 %d %d;\n", length * 4,
  92.                            start * 4 + length * 2,
  93.                            (pdev->height - lnum) * 4);
  94.                length = 0;
  95.             }
  96. #endif
  97.    }
  98.     fprintf(prn_stream, "DF;\nC1;\nE\n");
  99.     gs_free(in, line_size, 1, "cif_print_page(in)");
  100.     return 0;
  101. }
  102.